function AddFav() {
    var url = window.location.href.replace(/\?(\w*)\=(\d*)/, "");
    try {
        window.external.addFavorite(url, document.title);
    } catch(err) {
        try {
            window.sidebar.addPanel(document.title, url, "");
        } catch(err) {
            alert("加入收藏失败:" + err.description + "，请使用Ctrl+D进行添加");
        }
    }
}
function search() {
    $('#wd').focus(function() {
        if ($('#wd').val() == '请输入视频名、导演或主演') {
            $('#wd').val('');
        }
        if ($("#ss").html() !== '')($("#ss").css("display", "block"));
    });
    $('#wd').blur(function() {
        if ($('#wd').val() == '') {
            $('#wd').val('请输入视频名、导演或主演');
        }
        $("#ss").delay(500).hide("fast");
    });
}
function getcookies() {
    if ($.cookie("view_history")) {
        $("#history_box ul").html(" ") var $vso = $.cookie("view_history").split("|");
        var $vson = $vso.length
        for (var i = 0; i < $vson; i++) {
            var vsom = $vso[i].split("_");
            $("#history_box ul").append("<li><a href='" + vsom[0] + "' title='继续观看《" + vsom[2] + "》 重播'>" + ((vsom[2].length > 10) ? vsom[2].substring(0, 10) + "..": vsom[2]) + "</a><span>重播</span></li>")
        }
    }
}
$("#fav").click(function() {
    AddFav();
});
$("#fav2").click(function() {
    AddFav();
});
showsearch();
getcookies();
$("#history").mouseover(function() {
    $("#history_box").css("display", "block");
    $("#ifbg").css("display", "block")
}) $("#history").mouseout(function() {
    $("#history_box").css("display", "none");
    $("#ifbg").css("display", "none");
}) function shearchajax() {
    var val = $('#wd').val();
    var tit = encodeURIComponent(val);
    $("#ss").css("display", "block");
    if (tit.length > 0) {
        $.ajax({
            type: 'get',
            url: SitePath + 'index.php?s=video/searchajax/title/' + tit,
            timeout: 2000,
            success: function($html) {
                var kw = new RegExp(val, "gi");
                ser1 = $html.replace(/\+/g, "<i>");
                ser7 = $html.replace(/\+\d+/g, "");
                ser2 = ser1.replace(/\<i\>1/g, "<i>电影");
                ser3 = ser2.replace(/\<i\>2/g, "<i>电视");
                ser4 = ser3.replace(/\<i\>3/g, "<i>动漫");
                ser5 = ser4.replace(/\<i\>4/g, "<i>综艺");
                ser6 = ser5.replace(kw, "<b>" + val + "</b>");
                var se = ser6.split('|'),
                seh = '',
                hr = ser7.split('|');
                for (var i = 0; i < se.length - 1; i++) {
                    seh += "<a href='/index.php?s=video/search/wd/" + encodeURIComponent(hr[i]) + "' target='_blank'>" + se[i] + "</i></a>";
                } ($html != '') ? $("#ss").html(seh) : $("#ss").html("<a>没有精确结果</a>");
            }
        })
    } else {
        $("#ss").html("<a>请输入关键字</a>")
    }
}
$('#wd').keyup(function() {
    shearchajax();
});
$('#wd p').mouseover(function() {
    $('#wd p').removeClass("check");
    $(this).addClass("check");
})